Click here to Skip to main content
15,892,298 members
Articles / Mobile Apps / Windows Mobile

Creating Custom DirectShow SampleGrabber Filter for Windows Mobile

Rate me:
Please Sign up or sign in to vote.
4.73/5 (22 votes)
29 Nov 2008CPOL4 min read 597K   4.7K   57  
This article explains how to write your custom DirectShow SampleGrabber filter for Windows Mobile.
#pragma once
#include <assert.h>
#include <dshow.h>
#include "Resources.h"

#define FILTERNAME L"SampleGrabberFilter"

// Media types
const AMOVIESETUP_MEDIATYPE sudPinTypes [] =
{
    {&MEDIATYPE_Video,&MEDIASUBTYPE_RGB565},
    {&MEDIATYPE_Video,&MEDIASUBTYPE_YUY2},
};

// Pins
const AMOVIESETUP_PIN sudpPins[] =
{
    {
        L"VideoInput",              // Pin string name
        FALSE,                      // Is it rendered
        FALSE,                      // Is it an output
        FALSE,                      // Allowed none
        FALSE,                      // Likewise many
        &CLSID_NULL,                // Connects to filter
        NULL,                       // Connects to pin
        2,                          // Number of types
        sudPinTypes                 // Pin information
    },
    {
        L"VideoOutput",             // Pin string name
        FALSE,                      // Is it rendered
        FALSE,                      // Is it an output
        FALSE,                      // Allowed none
        FALSE,                      // Likewise many
        &CLSID_NULL,                // Connects to filter
        NULL,                       // Connects to pin
        2,                          // Number of types
        sudPinTypes                 // Pin information
    }
};

// Filters
const AMOVIESETUP_FILTER sudSampleGrabber =
{
	&CLSID_SampleGrabber,	    // Filter CLSID
	FILTERNAME,								// String name
	MERIT_NORMAL,							//MERIT_DO_NOT_USE,			// Filter merit
	2,												// Number of pins
	sudpPins									// Pin information
};


// define the filter class
class CSampleGrabber : 
public CTransInPlaceFilter, public ISampleGrabber
{
private:
MANAGEDCALLBACKPROC callback;
long m_Width;
long m_Height;
long m_SampleSize;
long m_Stride;

public:
// instantiation
CSampleGrabber( IUnknown * pOuter, HRESULT * phr, BOOL ModifiesData );
~CSampleGrabber();
static CUnknown *WINAPI CreateInstance(LPUNKNOWN punk, HRESULT *phr);

// IUnknown
DECLARE_IUNKNOWN;
STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void ** ppv);

// CTransInPlaceFilter
HRESULT CheckInputType(const CMediaType *pmt);
HRESULT SetMediaType(PIN_DIRECTION direction, const CMediaType *pmt);
HRESULT Transform(IMediaSample *pMediaSample);
HRESULT DecideBufferSize(IMemAllocator *pAlloc, ALLOCATOR_PROPERTIES *pProperties);
HRESULT GetMediaType(int iPosition, CMediaType *pMediaType);
HRESULT CheckTransform(const CMediaType *mtIn, const CMediaType *mtOut) {
	return NOERROR; }

// ISampleGrabber
STDMETHODIMP RegisterCallback(MANAGEDCALLBACKPROC mdelegate);
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer CST
Bulgaria Bulgaria
I am software engineering working for CST. My interests cover areas of Big Data, Cloud and Kubernetes.

For further information please contact me at akafazov@cst-bg.net

Comments and Discussions