The Machine Perception Toolbox

[Introduction]- [News]- [Download]- [Screenshots]- [Manual (pdf)]- [Forums]- [API Reference]- [Repository ]

 

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

MPBlinkDetectorFilter Class Reference

#include <MPBlinkDetectorFilter.h>

Collaboration diagram for MPBlinkDetectorFilter:

Collaboration graph
[legend]
List of all members.

Public Member Functions

HRESULT CheckInputType (const CMediaType *mtIn)
HRESULT CheckTransform (const CMediaType *mtIn, const CMediaType *mtOut)
HRESULT DecideBufferSize (IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *pProperties)
STDMETHODIMP GetClassID (CLSID *pClsid)
HRESULT GetMediaType (int iPosition, CMediaType *pMediaType)
STDMETHODIMP NonDelegatingQueryInterface (REFIID riid, void **ppv)
HRESULT ReadFromStream (IStream *pStream)
HRESULT ScribbleToStream (IStream *pStream)
virtual HRESULT StartStreaming ()
virtual HRESULT StopStreaming ()
HRESULT Transform (IMediaSample *pIn, IMediaSample *pOut)

Static Public Member Functions

CUnknown *WINAPI CreateInstance (LPUNKNOWN punk, HRESULT *phr)

Public Attributes

 DECLARE_IUNKNOWN

Private Member Functions

BOOL CanPerformMPBlinkDetectorFilter (const CMediaType *pMediaType) const
HRESULT Copy (IMediaSample *pSource, IMediaSample *pDest)
 MPBlinkDetectorFilter (TCHAR *tszName, LPUNKNOWN punk, HRESULT *phr)
HRESULT Transform (IMediaSample *pMediaSample)
 ~MPBlinkDetectorFilter ()

Private Attributes

CRefTime m_currentTime
int m_effect
int m_imgHeight
int m_imgWidth
FilterInterface m_interface
CRefTime m_lastValidTime
const long m_lBufferRequest
CCritSec m_MPBlinkDetectorFilterLock
CRefTime m_resetInterval

Constructor & Destructor Documentation

MPBlinkDetectorFilter TCHAR *  tszName,
LPUNKNOWN  punk,
HRESULT *  phr
[private]
 

Definition at line 102 of file MPBlinkDetectorFilter.cpp.

References m_currentTime, m_lastValidTime, and m_resetInterval.

Referenced by CreateInstance().

00103 : CTransformFilter(tszName, punk, CLSID_MPBlinkDetectorFilter)
00104 , m_effect(IDC_RED)
00105 , m_lBufferRequest(1)
00106 , CPersistStream(punk, phr)
00107 {
00108         char sz[60];
00109         GetProfileStringA("Adaptability", "ResetInterval", "30.0", sz, 60);
00110         m_resetInterval = COARefTime(atof(sz));
00111         
00112         m_currentTime = COARefTime(0.0);     
00113         m_lastValidTime = COARefTime(0.0);
00114         
00116         
00117         srand( (unsigned)time( NULL ) );
00118 
00119 } // (Constructor)

~MPBlinkDetectorFilter  )  [private]
 

Definition at line 473 of file MPBlinkDetectorFilter.cpp.

00473 {}


Member Function Documentation

BOOL CanPerformMPBlinkDetectorFilter const CMediaType *  pMediaType  )  const [private]
 

Definition at line 412 of file MPBlinkDetectorFilter.cpp.

References BOOL.

Referenced by CheckInputType(), and CheckTransform().

00413 {
00414         if (IsEqualGUID(*pMediaType->Type(), MEDIATYPE_Video)) {
00415                 if (IsEqualGUID(*pMediaType->Subtype(), MEDIASUBTYPE_RGB24)) {
00416                         VIDEOINFOHEADER *pvi = (VIDEOINFOHEADER *) pMediaType->Format();
00417                         return (pvi->bmiHeader.biBitCount == 24);
00418                 } 
00419         }
00420         return FALSE;
00421 } // CanPerformMPBlinkDetectorFilter

HRESULT CheckInputType const CMediaType *  mtIn  ) 
 

Definition at line 321 of file MPBlinkDetectorFilter.cpp.

References CanPerformMPBlinkDetectorFilter().

00322 {
00323         // check this is a VIDEOINFOHEADER type
00324         if (*mtIn->FormatType() != FORMAT_VideoInfo)
00325                 return E_INVALIDARG;
00326         // Can we transform this type
00327         if (CanPerformMPBlinkDetectorFilter(mtIn)) 
00328                 return NOERROR;
00329         return E_FAIL;
00330 }

Here is the call graph for this function:

HRESULT CheckTransform const CMediaType *  mtIn,
const CMediaType *  mtOut
 

Definition at line 339 of file MPBlinkDetectorFilter.cpp.

References CanPerformMPBlinkDetectorFilter().

00340 {
00341         if (CanPerformMPBlinkDetectorFilter(mtIn)) {
00342                 if (*mtIn == *mtOut)
00343                         return NOERROR;   
00344         }
00345         return E_FAIL;
00346 } // CheckTransform

Here is the call graph for this function:

HRESULT Copy IMediaSample *  pSource,
IMediaSample *  pDest
[private]
 

Definition at line 198 of file MPBlinkDetectorFilter.cpp.

References ASSERT, BYTE, FALSE, GetMediaType(), LONGLONG, m_imgHeight, m_imgWidth, m_interface, FilterInterface::printFrame(), RGBTRIPLE, and TRUE.

Referenced by Transform().

00199 {
00200         // Copy the media type
00201         
00202         AM_MEDIA_TYPE *pmt;
00203         pSource->GetMediaType(&pmt);
00204         pDest->SetMediaType(pmt);
00205         DeleteMediaType(pmt);
00206         
00207         // Copy the sample data
00208 
00209         BYTE *pSourceBuffer, *pDestBuffer;
00210         long lSourceSize = pSource->GetActualDataLength();
00211         long lDestSize  = pDest->GetSize();
00212         
00213         ASSERT(lDestSize >= lSourceSize);
00214         
00215         pSource->GetPointer(&pSourceBuffer);
00216         pDest->GetPointer(&pDestBuffer);
00217 
00218         m_interface.printFrame((RGBTRIPLE*)pSourceBuffer, m_imgWidth, m_imgHeight);
00219         CopyMemory( (PVOID) pDestBuffer,(PVOID) pSourceBuffer,lSourceSize);
00220         
00221         // Copy the sample times
00222         
00223         REFERENCE_TIME TimeStart, TimeEnd;
00224         if (NOERROR == pSource->GetTime(&TimeStart, &TimeEnd)) {
00225                 pDest->SetTime(&TimeStart, &TimeEnd);
00226         }
00227         
00228         LONGLONG MediaStart, MediaEnd;
00229         if (pSource->GetMediaTime(&MediaStart,&MediaEnd) == NOERROR) {
00230                 pDest->SetMediaTime(&MediaStart,&MediaEnd);
00231         }
00232         
00233         // Copy the Sync point property
00234         
00235         HRESULT hr = pSource->IsSyncPoint();
00236         if (hr == S_OK) {
00237                 pDest->SetSyncPoint(TRUE);
00238         }
00239         else if (hr == S_FALSE) {
00240                 pDest->SetSyncPoint(FALSE);
00241         }
00242         else {  // an unexpected error has occured...
00243                 return E_UNEXPECTED;
00244         }
00245                 
00246         // Copy the preroll property
00247         
00248         hr = pSource->IsPreroll();
00249         if (hr == S_OK) {
00250                 pDest->SetPreroll(TRUE);
00251         }
00252         else if (hr == S_FALSE) {
00253                 pDest->SetPreroll(FALSE);
00254         }
00255         else {  // an unexpected error has occured...
00256                 return E_UNEXPECTED;
00257         }
00258         
00259         // Copy the discontinuity property
00260         hr = pSource->IsDiscontinuity();
00261         
00262         if (hr == S_OK)
00263                 pDest->SetDiscontinuity(TRUE);
00264         
00265         else if (hr == S_FALSE)
00266                 pDest->SetDiscontinuity(FALSE);
00267         
00268         else 
00269                 return E_UNEXPECTED; // an unexpected error has occured...
00270         
00271         // Copy the actual data length
00272         long lDataLength = pSource->GetActualDataLength();
00273         pDest->SetActualDataLength(lDataLength);
00274         
00275         return NOERROR;
00276 } // Copy

Here is the call graph for this function:

CUnknown * CreateInstance LPUNKNOWN  punk,
HRESULT *  phr
[static]
 

Definition at line 128 of file MPBlinkDetectorFilter.cpp.

References MPBlinkDetectorFilter().

00129 {
00130         MPBlinkDetectorFilter *pNewObject = new MPBlinkDetectorFilter(NAME("Blink Detector MPLab"), punk, phr);
00131         if (pNewObject == NULL)
00132                 *phr = E_OUTOFMEMORY;
00133         return pNewObject;
00134 } // CreateInstance

Here is the call graph for this function:

HRESULT DecideBufferSize IMemAllocator *  pAlloc,
ALLOCATOR_PROPERTIES *  pProperties
 

Definition at line 356 of file MPBlinkDetectorFilter.cpp.

References ASSERT.

00357 {
00358         // Is the input pin connected
00359         if (m_pInput->IsConnected() == FALSE)
00360                 return E_UNEXPECTED;
00361         ASSERT(pAlloc);
00362         ASSERT(pProperties);
00363         HRESULT hr = NOERROR;
00364         pProperties->cBuffers = 1;
00365         pProperties->cbBuffer = m_pInput->CurrentMediaType().GetSampleSize();
00366         ASSERT(pProperties->cbBuffer);
00367         // Ask the allocator to reserve us some sample memory, NOTE the function
00368         // can succeed (that is return NOERROR) but still not have allocated the
00369         // memory that we requested, so we must check we got whatever we wanted
00370         ALLOCATOR_PROPERTIES Actual;
00371         hr = pAlloc->SetProperties(pProperties,&Actual);
00372         if (FAILED(hr))
00373                 return hr;
00374         ASSERT( Actual.cBuffers == 1 );
00375         if (pProperties->cBuffers > Actual.cBuffers ||
00376                 pProperties->cbBuffer > Actual.cbBuffer) {
00377                 return E_FAIL;  
00378         }
00379         return NOERROR;
00380 } // DecideBufferSize

STDMETHODIMP GetClassID CLSID *  pClsid  ) 
 

Definition at line 438 of file MPBlinkDetectorFilter.cpp.

00439 {
00440         return CBaseFilter::GetClassID(pClsid);
00441 } // GetClassID

HRESULT GetMediaType int  iPosition,
CMediaType *  pMediaType
 

Definition at line 390 of file MPBlinkDetectorFilter.cpp.

Referenced by Copy().

00391 {
00392         // Is the input pin connected
00393         if (m_pInput->IsConnected() == FALSE) 
00394                 return E_UNEXPECTED;
00395         // This should never happen
00396         if (iPosition < 0) 
00397                 return E_INVALIDARG;
00398         // Do we have more items to offer
00399         if (iPosition > 0)
00400                 return VFW_S_NO_MORE_ITEMS;
00401         *pMediaType = m_pInput->CurrentMediaType();
00402         return NOERROR;
00403 } // GetMediaType

STDMETHODIMP NonDelegatingQueryInterface REFIID  riid,
void **  ppv
 

Definition at line 143 of file MPBlinkDetectorFilter.cpp.

00144 {
00145         CheckPointer(ppv,E_POINTER);
00146         return CTransformFilter::NonDelegatingQueryInterface(riid, ppv);
00147 } // NonDelegatingQueryInterface

HRESULT ReadFromStream IStream *  pStream  ) 
 

Definition at line 464 of file MPBlinkDetectorFilter.cpp.

References m_effect, and READIN.

00465 {
00466         HRESULT hr;
00467         READIN(m_effect);
00468         return NOERROR;
00469 } // ReadFromStream

HRESULT ScribbleToStream IStream *  pStream  ) 
 

Definition at line 450 of file MPBlinkDetectorFilter.cpp.

References m_effect, and WRITEOUT.

00451 {
00452         HRESULT hr;
00453         WRITEOUT(m_effect);
00454         return NOERROR;
00455 } // ScribbleToStream

HRESULT StartStreaming  )  [virtual]
 

Definition at line 151 of file MPBlinkDetectorFilter.cpp.

00151                                              {
00152         return S_OK;
00153 }

HRESULT StopStreaming  )  [virtual]
 

Definition at line 157 of file MPBlinkDetectorFilter.cpp.

00157                                             {
00158         return S_OK;
00159 }

HRESULT Transform IMediaSample *  pMediaSample  )  [private]
 

Definition at line 281 of file MPBlinkDetectorFilter.cpp.

References BYTE, fclose(), fid, fprintf(), m_currentTime, m_imgHeight, m_imgWidth, m_interface, m_lastValidTime, and FilterInterface::runInterface().

00282 {
00283         AM_MEDIA_TYPE* pType = &m_pInput->CurrentMediaType();
00284         VIDEOINFOHEADER *pvi = (VIDEOINFOHEADER *) pType->pbFormat;
00285         
00286         BYTE *pData;                // Pointer to the actual image buffer
00287         pMediaSample->GetPointer(&pData);
00288 
00289         // Get the image properties from the BITMAPINFOHEADER
00290 
00291         m_imgWidth = pvi->bmiHeader.biWidth;
00292         m_imgHeight = pvi->bmiHeader.biHeight;
00293         
00294         m_interface.runInterface(pData, m_imgWidth, m_imgHeight); 
00295 
00297 // measure frame rate and output to file every 30 frames.
00298 // #define BENCHMARK
00299 #ifdef BENCHMARK
00300         const float alpha = .1f;
00301         static double avgtimeDiff = 60;
00302         static int count = 0;
00303         double curtimeDiff = m_currentTime.Millisecs() - m_lastValidTime.Millisecs();
00304         avgtimeDiff = curtimeDiff * alpha + avgtimeDiff * (1-alpha);
00305         if (count++ % 30 == 0) {
00306                 FILE *fid = fopen("benchmark.txt", "a");
00307                 fprintf(fid, "%.2f\n", 1000.0/avgtimeDiff);
00308                 fclose(fid);
00309         }
00310 #endif
00311 
00312 
00313         m_lastValidTime = m_currentTime;
00314 
00315         return NOERROR;
00316 }

Here is the call graph for this function:

HRESULT Transform IMediaSample *  pIn,
IMediaSample *  pOut
 

Definition at line 176 of file MPBlinkDetectorFilter.cpp.

References Copy(), and m_currentTime.

00177 {
00178         // Copy the properties across
00179         HRESULT hr = Copy(pIn, pOut);
00180         if (FAILED(hr)) {
00181                 return hr;
00182         }
00183         
00184         CRefTime temp;
00185         pIn->GetTime((REFERENCE_TIME *) &m_currentTime, (REFERENCE_TIME *)&temp);
00186         
00187         return Transform(pOut);
00188         
00189 } // Transform

Here is the call graph for this function:


Member Data Documentation

DECLARE_IUNKNOWN
 

Definition at line 12 of file MPBlinkDetectorFilter.h.

CRefTime m_currentTime [private]
 

Definition at line 50 of file MPBlinkDetectorFilter.h.

Referenced by MPBlinkDetectorFilter(), and Transform().

int m_effect [private]
 

Definition at line 47 of file MPBlinkDetectorFilter.h.

Referenced by ReadFromStream(), and ScribbleToStream().

int m_imgHeight [private]
 

Definition at line 56 of file MPBlinkDetectorFilter.h.

Referenced by Copy(), and Transform().

int m_imgWidth [private]
 

Definition at line 55 of file MPBlinkDetectorFilter.h.

Referenced by Copy(), and Transform().

FilterInterface m_interface [private]
 

Definition at line 54 of file MPBlinkDetectorFilter.h.

Referenced by Copy(), and Transform().

CRefTime m_lastValidTime [private]
 

Definition at line 51 of file MPBlinkDetectorFilter.h.

Referenced by MPBlinkDetectorFilter(), and Transform().

const long m_lBufferRequest [private]
 

Definition at line 48 of file MPBlinkDetectorFilter.h.

CCritSec m_MPBlinkDetectorFilterLock [private]
 

Definition at line 46 of file MPBlinkDetectorFilter.h.

CRefTime m_resetInterval [private]
 

Definition at line 52 of file MPBlinkDetectorFilter.h.

Referenced by MPBlinkDetectorFilter().


The documentation for this class was generated from the following files:
Generated on Mon Nov 8 17:08:33 2004 for MPT by  doxygen 1.3.9.1