Microsoft DirectX 8.1 (C++)

A Sample Transform Filter Declaration

This sample illustrates a true minimalist filter, which does nothing except demonstrate the least you must implement for a filter. It uses the transform-in-place classes and derives its filter class from the CTransInPlaceFilter class. Following is the class declaration for the derived filter class CnullNull:

// CNullNull
//
class CNullNull
    : public CTransInPlaceFilter
{

public:

    static CUnknown *CreateInstance(LPUNKNOWN punk, HRESULT *phr);

    DECLARE_IUNKNOWN;

    LPAMOVIESETUP_FILTER GetSetupData()
    {
        return &sudNullNull;
    }

private:

    // Constructor. Just calls the base class constructor.
    CNullNull(TCHAR *tszName, LPUNKNOWN punk, HRESULT *phr)
        : CTransInPlaceFilter (tszName, punk, CLSID_NullNull, phr)
    { }

    // Overrides the pure virtual Transform of CTransInPlaceFilter base class.
    // The "real work" of a transform is done by altering *pSample. 
    // The Null transform leaves it alone.
    HRESULT Transform(IMediaSample *pSample){ return NOERROR; }

    // This filter accepts any input type. 
    // (It would return S_FALSE for any it did not accept.)
    HRESULT CheckInputType(const CMediaType* mtIn) { return S_OK; }
};

This example illustrates the following basic member functions required in the base class.

Member function Behavior
CreateInstance Needed by every filter so that it can be instantiated as a COM object.
GetSetupData Overrides CBaseFilter::GetSetupData and is used to provide the class with information required to register this particular filter. In this case, it provides the address of a structure defined in the Nullnull.cpp file included in the SDK.
CNullNull Class constructor, which typically just calls the base class constructor.
Transform Overrides CTransInPlaceFilter::Transform and does the main work of CNullNull, which in this case is nothing.
CheckInputType Overrides CTransformFilter::CheckInputType to verify the media type during connection, and in this case accepts any media type offered, since it will simply pass it along to the next filter in line.

Note that, strictly speaking, GetSetupData is required only if you want your filter to be self-registering. However, since the base classes implement this feature and it is easy to implement, it is a good idea to include this in your base class.